﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SoucreGame.DTO;
using SoucreGame.GLO;

namespace SoucreGame.BUS
{
    class CBusiKyNang
    {

        public CInfoKyNang KyNang { get; set; }

        int frameTimeLine = 0;
        ContentManager Content { get; set; }
        GameTime GameTime { get; set; }
        SpriteBatch SpriteBatch { get; set; }

        private void LoadDuLieu()
        {
            this.KyNang.Ten = KyNang.Ten;
            this.KyNang.PhamViAnhHuong = KyNang.PhamViAnhHuong;
            this.KyNang.SucTanCong = KyNang.SucTanCong;
            this.KyNang.HinhTheHien = KyNang.HinhTheHien;
            this.KyNang.ViTriAnh = KyNang.ViTriAnh;
            this.KyNang.TocDoDiChuyen = KyNang.TocDoDiChuyen;
            this.KyNang.SttAnhBatDau = KyNang.SttAnhBatDau;
            this.KyNang.SoLuongAnh = KyNang.SoLuongAnh;
            this.KyNang.VecPos = KyNang.VecPos;
            this.KyNang.ChuKyDiChuyen = KyNang.ChuKyDiChuyen;
        }

        public CBusiKyNang(ContentManager content, GameTime gameTime, SpriteBatch spriteBatch)
        {
            this.GameTime = gameTime;
            this.Content = content;
            this.SpriteBatch = spriteBatch;
            KyNang = new CInfoKyNang(content, gameTime, spriteBatch);
            LoadDuLieu();
        }

        public CBusiKyNang()
        {
            KyNang = new CInfoKyNang(Content, GameTime, SpriteBatch);
            LoadDuLieu();
        }

        public enum chon { DiChuyen, DungYen };
        public chon hanhDong;

        public virtual void Update(GameTime gameTime)
        {
            frameTimeLine += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            switch (hanhDong)
            {
                case chon.DiChuyen:
                    {
                        DiChuyen();
                        break;
                    }
                case chon.DungYen:
                    {
                        DungYen();
                        break;
                    }
            }
        }

        public virtual void DiChuyen()
        {
            if (frameTimeLine >= KyNang.ChuKyDiChuyen)
            {
                KyNang.SttAnhBatDau++;
                if (KyNang.SttAnhBatDau > KyNang.SoLuongAnh)
                    KyNang.SttAnhBatDau = KyNang.SoLuongAnh;
                KyNang.VecPos = new Vector2(KyNang.VecPos.X + KyNang.TocDoDiChuyen, KyNang.VecPos.Y);
                frameTimeLine = 0;
            }
        }

        public virtual void DungYen()
        {
            if (frameTimeLine >= KyNang.ChuKyDiChuyen)
            {
                KyNang.SttAnhBatDau++;
                if (KyNang.SttAnhBatDau > KyNang.SoLuongAnh)
                    KyNang.SttAnhBatDau = KyNang.SoLuongAnh;

                frameTimeLine = 0;
            }
        }

        public virtual void Draw(GameTime gameTime)
        {
            switch (hanhDong)
            {
                case chon.DiChuyen:
                    {
                        this.SpriteBatch.Draw(this.KyNang.HinhTheHien, this.KyNang.VecPos, this.KyNang.ViTriAnh[this.KyNang.Ten + this.KyNang.SttAnhBatDau], Color.White);
                        break;
                    }
                case chon.DungYen:
                    {
                        this.SpriteBatch.Draw(this.KyNang.HinhTheHien, this.KyNang.VecPos, this.KyNang.ViTriAnh[this.KyNang.Ten + this.KyNang.SttAnhBatDau], Color.White);
                        break;
                    }
            }
        }

    }
}
